#$start=41000001; 
#$stop=44200000;
chomp($ARGV[0]);
chomp($ARGV[1]);
chomp($ARGV[2]);
chomp($ARGV[3]);
$count_total=$ARGV[1];
$start=$ARGV[2];
$stop=$ARGV[3];
open(MAT,"$ARGV[0]/Maternal.vcf") or die "no file found $ARGV[0]/Maternal.vcf\n";
open(PAT,"$ARGV[0]/Paternal.vcf") or die "no file found $ARGV[0]/Paternal.vcf\n";
$total=$stop-$start;
$total_maternal=$total;
while(<MAT>)
{
	chomp($_);
	if($_ !~ m/^#/)
	{
		@array=split("\t",$_);
		@des=split('=',$array[7]);
		$svlen=pop(@des);
		@num=split(':',$array[9]);
		$num=pop(@num);
		if($array[4] =~ m/DEL/)
                {
			$total_maternal=$total_maternal-$num*$svlen
		}
		elsif($array[4] =~ m/DUP/)
		{
			$total_maternal=$total_maternal+$num*$svlen
		}
	}
}
$total_paternal=$total;
while(<PAT>)
{
        chomp($_);
        if($_ !~ m/^#/)
        {
                @array=split("\t",$_);
                @des=split('=',$array[7]);
                $svlen=pop(@des);
                @num=split(':',$array[9]);
                $num=pop(@num);
                if($array[4] =~ m/DEL/)
                {
                        $total_paternal=$total_paternal-$num*$svlen
                }
                elsif($array[4] =~ m/DUP/)
                {
                        $total_paternal=$total_paternal+$num*$svlen
                }
        }
}

close(MAT);
close(PAT);
#$total_maternal=int($total_maternal/2);
#$total_paternal=int($total_paternal/2);
$count_total_maternal=int(($total_maternal/$total)*$count_total/2);
$count_total_paternal=int(($total_paternal/$total)*$count_total/2);
print "$count_total\n$count_total_maternal\n$count_total_paternal\n";
